import api from '../../api';
import { message } from 'antd';

export default {
  namespace: 'informationM',
  state: {
    basicInfo: {}, // 理财直融基础信息
    formDatas: {
      // 非理财直融
      baseInfo: {}, //基本信息
      reportInfo: {}, //监管报表信息
      files: [], //资产包
      zgtzptNonstandarCashFlows: [], //赎回计息
    },
  },
  effects: {
    // 根据id获取详情
    *getDataById({ payload }, { call, put }) {
      const res = yield call(api.nonstandarmaintenanceNew.getDataById, payload);
      if (res && res.code == 0 && JSON.stringify(res.data) != '{}') {
        yield put({
          type: 'setState',
          payload: {
            formDatas: res.data,
          },
        });
      } else {
        message.error(`获取详情失败，失败原因：${res?.msg}`);
      }
    },

    // 编辑理财直融信息
    *editInformationById({ payload }, { call, put }) {
      const res = yield call(api.moneyInformation.editInformationById, payload);
      if (res && res.success) {
        yield put({
          type: 'setState',
          payload: {
            basicInfo: res.data,
          },
        });
      } else {
        message.error(`获取信息失败，失败原因：${res?.message}`);
      }
    },
  },

  reducers: {
    setState(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};
